#ifndef _Scene_H_
#define _Scene_H_
#include "model.h"
#include "bullet.h"
#include <QtOpenGL/qgl.h>
#include <QtCore/QVector>
#include <QtCore/QMap>

/********************************
  Board Cells states:
*********************************/
enum  cell_state_t {
    empty = 0,
    wall = 10,
    player = 12,
    enemy0 = 13,
    enemy1 = 14,
    enemy2 = 15,
    enemy3 = 16,
    enemy4 = 17,
    enemy5 = 18
};

enum game_state_t {
    play, victory, defeat
};

class Scene
{
 private:
	
  // Dades de l'escena
  int heroOrientation;
  int m_rows;
  int m_columns;
  QVector<cell_state_t> m_tauler;
  QVector<int> enemiesOrtientation;
  QVector<Bullet> m_bullets;
  int m_NumBaddies;
  float hero_offset;

  Model m_hero;
  Model m_enemy;

 public:
  static MaterialLib matlib;	  // col·lecció de materials

  Scene();
  ~Scene();

  void Render(bool);
  void FalseRender();

  void PintaCaixa (Point &posini, Point &posfi);
  void PintaEsfera(Point& centre, float radi, int subdivisions, Color& c);

  void boundingSphere(Point& center, float& radix);
  void setHero(const Model&);
  void setEnemy(const Model&);
  void RotateHero(int);
  void AdvanceCharacter(int step, int& r, int& c, int orientation, cell_state_t kind);
  void AdvanceHero(int step);
  void initTauler(int rows = 10, int columns = 10);
  void initEnemies(int number = 3);
  game_state_t MoureEnemics(int);
  bool MoureEnemicsRandom();
  bool MoureEnemicsPepe();
  bool MoureEnemicsPathFind();
  void Flip(int, int);
  void GetSize(int&, int&);
  void SubjectiveView(double&, double&, double&, double&, double&, double&);
  void CharacterOffset(float);
  void Fire();
  void AnimateBullets();
private:

  void RenderModel(Model&, float rotation = 0.0f);
  void HeroLocation(int&, int&);
  int EnemyLocation(int, const QVector<cell_state_t>&, int&);
  int step(const int step, int& startR, int& startC, const int orientation,
           const int finalR, const int finalC,
           const QVector<cell_state_t>& tauler);
  int pathfinding(int& startR, int& startC, const int orientation, const int finalR, const int finalC, const QVector<cell_state_t>& tauler);
  int minCost(int, int, int, int);
  void materialsTerra();
  void materialsObstacle();
};

#endif

